package com.wteam.dragon.shop.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wteam.dragon.shop.pojo.bean.Brand;
import com.wteam.dragon.shop.pojo.vo.BrandVo;
import com.wteam.dragon.shop.service.BrandService;
import com.wteam.dragon.system.aop.log.log.Log;
import com.wteam.dragon.system.basebean.bean.ResultMessage;
import com.wteam.dragon.system.basebean.vo.PageVo;
import com.wteam.dragon.system.util.BeanUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author 陈晓辉
 * @Date 2021/3/23 17:17
 */
@RestController
@RequiredArgsConstructor
@Api(tags = "品牌")
@RequestMapping("brand")
public class BrandController {
    private final BrandService brandService;

    @Log("添加品牌")
    @ApiOperation("添加品牌")
    @PostMapping("addBrand")
    @PreAuthorize("@el.check('addBrand')")
    public ResultMessage addBrand(@Validated BrandVo brandVo){
        Brand brand = BeanUtil.from(brandVo, Brand.class);
        return brandService.addBrand(brand);
    }

    @Log("删除品牌")
    @ApiOperation("删除品牌")
    @DeleteMapping("delBrand")
    @PreAuthorize("@el.check('delBrand')")
    public ResultMessage delBrand(@RequestParam List<Long> ids){
        return brandService.delBrand(ids);
    }

    @Log("更改品牌")
    @ApiOperation("更改品牌")
    @PutMapping("editBrand")
    @PreAuthorize("@el.check('editBrand')")
    public ResultMessage editBrand(@Validated BrandVo brandVo){
        Brand brand = BeanUtil.from(brandVo, Brand.class);
        return brandService.editBrand(brand);
    }

    @Log("分页获得品牌")
    @ApiOperation("分页获得品牌")
    @GetMapping("pageBrand")
    @PreAuthorize("@el.check('pageBrand')")
    public ResultMessage getBrand(PageVo<Brand> pageVo, String name, Boolean showStatus){
        Page<Brand> page = BeanUtil.fromPage(pageVo);
        return brandService.pageBrand(page, name, showStatus);
    }

    @Log("获得品牌详情")
    @ApiOperation("获得品牌详情")
    @GetMapping("getBrand")
    @PreAuthorize("@el.check('getBrand')")
    public ResultMessage getBrand(Long id){
        return brandService.getBrand(id);
    }

    @Log("批量更改显示状态")
    @ApiOperation("批量更改显示状态")
    @GetMapping("editShowStatus")
    @PreAuthorize("@el.check('editShowStatus')")
    public ResultMessage editShowStatus(List<Long> ids, Boolean showStatus){
        return brandService.editShowStatus(ids, showStatus);
    }

    @Log("批量更改厂家制造商状态")
    @ApiOperation("批量更改厂家制造商状态")
    @GetMapping("editFactoryStatus")
    @PreAuthorize("@el.check('editFactoryStatus')")
    public ResultMessage editFactoryStatus(List<Long> ids, Boolean factoryStatus){
        return brandService.editFactoryStatus(ids, factoryStatus);
    }

    @Log("获得品牌名字列表")
    @ApiOperation("获得品牌名字列表")
    @GetMapping("getBrandName")
    @PreAuthorize("@el.check('getBrandName')")
    public ResultMessage getBrandName(){
        return brandService.getBrandName();
    }

}
